package com.ricchieri.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.ricchieri.dao.interf.IMeanPaymentDao;
import com.ricchieri.filter.BasicFilter;
import com.ricchieri.model.MeanPayment;
import com.ricchieri.service.interf.IMeanPaymentService;
import com.ricchieri.util.FacesUtil;

@Transactional(readOnly = true)
public class MeanPaymentService implements IMeanPaymentService, Serializable {
	private static final long serialVersionUID = -5725169954683422490L;
	IMeanPaymentDao meanPaymentDao;
	
	@Override
	@Transactional(readOnly = true)
	public List<MeanPayment> getAllMeanPayment() {
		BasicFilter filter = new BasicFilter();
		return meanPaymentDao.getAllMeanPayment(filter);
	}

	public IMeanPaymentDao getMeanPaymentDao() {
		return meanPaymentDao;
	}

	public void setMeanPaymentDao(IMeanPaymentDao meanPaymentDao) {
		this.meanPaymentDao = meanPaymentDao;
	}
	
	@Override
	public MeanPayment getMeanPaymentById(BasicFilter meanPaymentFilter) {
		return getMeanPaymentDao().getMeanPaymentById(meanPaymentFilter);
	}		
	
	@Override
	public Map<String, String> getComboMeanPayment() {
		List<MeanPayment> meanPaymentValues = this.getAllMeanPayment();

		HashMap<String, String> meanPaymentCombo = new LinkedHashMap<String, String>();

		for (MeanPayment meanPayment : meanPaymentValues) {
			meanPaymentCombo.put(FacesUtil.getMessage(meanPayment.getDescription()), String.valueOf(meanPayment.getId()));
		}

		return meanPaymentCombo;
	}
}
